using System;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Package;

namespace MH.WsdlWorks
{
    public abstract class NodeBase : SimpleHierarchyNode
    {
        public NodeBase(SimpleProjectNode root, string directoryPath) 
            : base(root)
        {
            this.VirtualNodeName = directoryPath.TrimEnd('\\');
        }

        protected abstract override SimpleNodeProperties CreatePropertiesObject();

        protected internal override void DeleteFromStorage(string path)
        {
            // TODO: delete this wsdl node from the project file
            base.DeleteFromStorage(path);
        }

        public override object GetAutomationObject()
        {
            // TODO: return an automation object
            return null;
        }

        public abstract override object GetIconHandle(bool open);

        public override string Url
        {
            get 
            { 
                return Path.Combine(Path.GetDirectoryName(this.ProjectMgr.Url), this.VirtualNodeName) + "\\"; 
            }
        }

        public override string Caption
        {
            get 
            {
                // it might have a backslash at the end... 
                // and it might consist of Grandparent\parent\this\
                string caption = this.VirtualNodeName;
                string[] parts;
                parts = caption.Split(Path.DirectorySeparatorChar);
                caption = parts[parts.GetUpperBound(0)];
                return caption;
            }
        }

        public abstract override Guid ItemTypeGuid
        {
            get;
        }

        public override string GetMkDocument()
        {
            return this.Url;
        }
    }
}
